package com.jerry.template.module.mianpage.shouye.recommend.home.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.jerry.template.R;
import com.jerry.template.base.BaseActivity;
import com.jerry.template.base.BaseFragment;
import com.jerry.template.constant.Urls;
import com.jerry.template.module.mianpage.shouye.recommend.home.adapter.UserFragmentVpAdapter;
import com.jerry.template.module.mianpage.shouye.recommend.home.entity.RecommendUserDetailEntity;
import com.jerry.template.module.mianpage.shouye.recommend.home.entity.TouGaoEntity;
import com.jerry.template.module.mianpage.shouye.recommend.home.fragment.UserDetailFragment;
import com.jerry.template.utils.EventMessage;
import com.jerry.template.utils.OkHttpUtils;
import com.jerry.template.views.SlidingTabLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

public class UserDetailActivity extends BaseActivity {

    private String user_id;

    //用户详情控件
    @BindView(R.id.backRecommend)
    public ImageView backRecommend;

    @BindView(R.id.user_name)
    public TextView userName;

    @BindView(R.id.jubao)
    public TextView jubao;

    @BindView(R.id.userPic)
    public ImageView userPic;

    @BindView(R.id.signal)
    public TextView signal;

    @BindView(R.id.concern)
    public Button concern;

    @BindView(R.id.secretTalk)
    public Button secretTalk;

    @BindView(R.id.followers)
    public TextView followers;

    @BindView(R.id.followings)
    public TextView followings;

    @BindView(R.id.point)
    public TextView point;

    @BindView(R.id.description)
    public TextView description;
    //用户详情数据
    private RecommendUserDetailEntity userDetail;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_user_detail;
    }

    @Override
    protected void initViews() {
        //获取从推荐页 传过来的用户Id
        Intent intent = getIntent();
        user_id = intent.getStringExtra("user_id");
//        Toast.makeText(this, user_id, Toast.LENGTH_SHORT).show();
        //加载用户详细页
        loadContentDetail();
        Map<String,String>params  = new HashMap<>();
        params.put("user_id",user_id);
        UserDetailFragment fragment = BaseFragment.newInstance(UserDetailFragment.class,params);
        getSupportFragmentManager().beginTransaction().replace(R.id.user_TSP_detail,fragment).commit();

    }

    @Override
    protected void loadData() {

    }
    //获取网络访问后加载完的详细内容
    @Override
    protected void postEventResult(@NonNull EventMessage message) {
        if (message.type.equals(Urls.RECOMMEND_CONTENT_URL_BEFORE +
                user_id
                + Urls.RECOMMEND_CONTENT_URL_AFTER)){
            String result = message.result;
            Gson gson = new Gson();
            //解析用户Json格式内容
            userDetail = gson.fromJson(result,RecommendUserDetailEntity.class);
            //讲解析出来的内容显示到指定控件上
            userName.setText(userDetail.getData().getName());
            Glide.with(this).load(userDetail.getData().getAvatar_url()).into(userPic);
            signal.setText(userDetail.getData().getCity());
            followers.setText(userDetail.getData().getFollowers()+"");
            followings.setText(userDetail.getData().getFollowings()+"");
            point.setText(userDetail.getData().getPoint()+"");
            description.setText(userDetail.getData().getDescription());
        }
    }
    //访问网络为了得到用户详细信息
    private void loadContentDetail() {
        OkHttpUtils.postSubmitForm(
                Urls.RECOMMEND_CONTENT_URL_BEFORE +
                        user_id
                        + Urls.RECOMMEND_CONTENT_URL_AFTER
                , null);
    }
}
